﻿class ManagedSound extends Sound {
	var _channel:SoundChannel;
	var _pausePosition:Number;
	var _playing:Boolean;
	
	function ManagedSound() {
		super();
		_channel = null;
		_pausePosition = 0;
		_playing = false;
	}
	
	function onSoundComplete():Void {
		if (_channel) {
			_channel.remove(this);
		}
	}
	
	function start():Void {
		_playing = true;
		super.start();
	}
	
	function stop():Void {
		_playing = false;
		_pausePosition = 0;
		super.stop();
	}
	
	function _stopId(id:String):Void {
		super.stop(id);
	}
	
	function pause():Void {
		if (!_playing) return;
		_playing = false;
		_pausePosition = this.position;
		super.stop();
	}
	
	function resume():Void {
		if (_playing) return;
		_playing = true;
		// start con position no implementado aún
		// llamamos directamente al start de Sound
		// la posicion de start se indica en segundos no en milisegundos (?)
		super.start(_pausePosition/1000);
	}
}
